package servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dbmanager.*;
import domain.KLIENT;

@WebServlet("/Servlet1")
public class NovyKlientServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    
    public NovyKlientServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		request.setCharacterEncoding("UTF-8");
		
		String meno = request.getParameter("meno");
		String priezvisko = request.getParameter("priezvisko");
		String rodc = request.getParameter("rod_cislo");
		String adresa = request.getParameter("adresa");
		String telc = request.getParameter("tel_cislo");
		String email = request.getParameter("email");
		
		MSSQL ms = new MSSQL("127.0.0.1");
		SQLManager s = ms.connect();
		
		Integer id = s.vratMaxID("BA", "KLIENT");
		KLIENT k = new KLIENT(id + 1,1,meno,priezvisko,rodc,adresa,email,telc,null,null);
		
		s.insertN(k,"BA");
		ms.disconnect(s.getConnection());
		
		request.setAttribute("k", k);
		request.getRequestDispatcher("Klient.jsp").forward(request, response);
	}
}
